package com.interesting.client.UI.setting;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.interesting.R;
import com.interesting.base.core.BaseFragment;
import com.interesting.base.http.HttpUtil;

/** 关于最有趣 */
public class AboutFragment extends BaseFragment {

	private WebView webView; // 内容

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.setting_about_fragment, container, false);
		webView = (WebView) v.findViewById(R.id.about_fragment_webview);
		return v;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		new AboutUsAsync().execute();
	}

	private class AboutUsAsync extends AsyncTask<String, Void, JSONObject> {

		@Override
		protected JSONObject doInBackground(String... params) {
			Map<String, String> request = new HashMap<String, String>();
			request.put("act", "about");
			request.put("Id", "1");
			return HttpUtil.parseResult(HttpUtil.post(request));
		}

		@Override
		protected void onPostExecute(JSONObject result) {
			if (result != null) {
				try {
					webView.loadData(result.getString("content"), "text/html", "utf-8");
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			super.onPostExecute(result);
		}
	}
}
